package com.ly.chatsimple

import android.app.Application
import com.ly.chatsimple.tcp.TcpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.isActive

class App : Application() {
    private var mainScope = CoroutineScope(Dispatchers.Main + SupervisorJob())

    override fun onCreate() {
        super.onCreate()
        if (!mainScope.isActive) {
            mainScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
        }
        TcpClient.init(this@App, mainScope)
    }

    override fun onTerminate() {
        super.onTerminate()
        TcpClient.release()
    }
}